package com.zhu.algorithm.jzOffer.otherJZ;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: zhujiabao
 * @Date: 2023/01/28/20:18
 * @Description: JZ58 左旋转字符串
 */
public class Solution58 {
    public static void main(String[] args) {
        String str = "5485zhuzhumen4567";
        System.out.println(new Solution58().LeftRotateString(str,6));
    }

    public String LeftRotateString(String str,int n) {
        if (str == null || str.length()==0) {
            return "";
        }
        if ( n == 0) {
            return str;
        }
        int length = str.length();
        char[] string = str.toCharArray();
        char[] newString = new char[length];
        int order = n % length;
        int temp = order;
        for (int i = 0; i < length; i++,temp++) {
            if (temp >= length) {
                temp = 0;
            }
            newString[i] = string[temp];
        }
        return new String(newString);
    }
}
